package com.wanlian.candy.controller;

import com.wanlian.json.JsonResult;
import com.wanlian.json.JsonStringUtil;
import com.wanlian.model.ResultModel;
import com.wanlian.service.StorageServices;
import com.wanlian.vo.DeviceFileVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/devicefile")
public class DeviceFileController {

    @Autowired
    private StorageServices storageServices;


    @RequestMapping("/update")
    @ResponseBody
    public String updateDeviceFilesByKey(@RequestBody String data) {
        DeviceFileVo deviceFileVo = JsonStringUtil.readValue(data, DeviceFileVo.class);
        deviceFileVo.transferToItems();
        if (deviceFileVo != null) {
            if (deviceFileVo.getItems() != null) {
                if (deviceFileVo.getItems().size() > 0) {
                    ResultModel resultModel = storageServices.doUpdateStorageItems(deviceFileVo);
                    return new JsonResult().Serailze(resultModel);
                }
            }
        }
        return new JsonResult().Serailze(false, "para:files can not empty");
    }


    //todo:需要补充完整
    @RequestMapping("/item/type/{type}")
    @ResponseBody
    public String queryItemsByType(@PathVariable("type") int type) {

        return new JsonResult().Serailze(false, "para:files can not empty");
    }

}
